<?php
/**
 * @annotate 行业，职位增删改查
 * @group   Admin/Haiyin
 * @author   mengke.yue <mengke.yue@gmail.com>
 */
class PositionAction extends BaseAction {
	protected $aVerify = array(
   	'index'
  	);//需要验证的方法
	public function hangye(){
		$this->assign('Title',"行业设置");
		$Hangye  = D('Hangye');
		$result = $Hangye->select_hangye();
		$this->assign('list',$result);
		$this->display();
	}
	public function position_list(){
		$Hangye  = D('Hangye');
		$hangye = $Hangye->select_hangye();
		$this->assign('hangye',$hangye);
		$this->assign('Title',"职位列表");
		import('ORG.Util.Page');//导入分页类
		if ($this->isPost()){
			$map['hid'] = getRequest('hid');
			$map['is_del'] = 0;
		}else{
			if(getRequest('hid')!=""){
				$map['hid'] = getRequest('hid');
			}
			$map['is_del'] = 0;
		}
		$count =D('position')->where($map)->order('ctime desc')->count();
		$Page = new Page($count,20);
        $show = $Page ->show();
		$list = D('position')->where($map)->order('ctime desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		$hang = D('hangye')->getField('id','h_name');
		foreach ($list as $k=> $v) {
			$list[$k]['hangye'] = D('hangye')->where(array('id'=>$list[$k]['hid']))->getField('h_name');
		}

		$this->assign('page',$show);
		$this->assign('list',$list);
		$this->display();
	}
	public function add_hangye(){
		$this->assign('Title',"添加行业");
		$this->checkPost();
		$Hangye  = D('Hangye');
		$data['h_name'] = getRequest('h_name');
		$data['ctime'] = time();
		$result = $Hangye->add_hangye($data);
		$url = U('Position/hangye');
		if ($result) {
			$this->assign("jumpUrl",$url);//跳转
	        $this->success("添加成功！");
        }
	}
	public function add_position(){
		$this->assign('Title',"添加职位");
		$Hangye  = D('Hangye');
		$result = $Hangye->select_hangye();
		$this->assign('list',$result);
		$this->checkPost();
		$Position  = D('Position');
		$data['hid'] = getRequest('hid');
		$data['p_name'] = getRequest('p_name');
		$data['ctime'] = time();
		$result = $Position->add_position($data);
		$url = U('Position/position_list');
		if ($result) {
			$this->assign("jumpUrl",$url);//跳转
	        $this->success("添加成功！");
        }
	}
	public function del_hangye(){
		$id = getRequest('id');
		$da = D('Hangye')->del_hangye($id);
		if($da){
			$this->ajaxReturn('','success',1);
		}else{
			$this->ajaxReturn('','error',0);
		}
	}
	public function del_position(){
		$id = getRequest('id');
		$da = D('Position')->del_position($id);
		if($da){
			$this->ajaxReturn('','success',1);
		}else{
			$this->ajaxReturn('','error',0);
		}
	}
	
	public function edit_hangye(){
		$this->assign('Title',"修改行业");
		$Hangye  = D('Hangye');
		$id = getRequest('id');
		$list = $Hangye->get_hangye($id);
		$this->assign('list',$list);
		$this->checkPost();
		$data['h_name'] = getRequest('h_name');
		$id = getRequest('id');
		$result = $Hangye->edit_hangye($id,$data);
		$url = U('Position/hangye');
		if ($result) {
			$this->assign("jumpUrl",$url);//跳转
	        $this->success("修改成功！");
        }
	}

	public function edit_position(){
		$this->assign('Title',"修改职位");
		$Position  = D('Position');
		$pid = getRequest('pid');
		$posi = $Position->get_position($pid);
		$Hangye  = D('Hangye');
		$list = $Hangye->select_hangye();
		$this->assign('list',$list);
		$this->assign('posi',$posi);
		$this->checkPost();
		$data['hid'] = getRequest('hid');
		$data['p_name'] = getRequest('p_name');
		$data['ctime'] = time();
		$pid = getRequest('pid');
		$result = $Position->edit_position($pid,$data);
		$url = U('Position/position_list');
		if ($result) {
			$this->assign("jumpUrl",$url);//跳转
	        $this->success("修改成功！");
        }
       
	}


}
?>